package it.unibo.location.test.unit;

import static org.junit.Assert.*;

import java.util.Date;

import it.unibo.location.ILocation;

import org.junit.Test;

public abstract class LocationTestCase {

	public abstract ILocation createConcreteLocation(double longitude, double latitude, double altitude);

	@Test
	public void testDistanceTo() 
	{
		// 1 km
		ILocation location1 = createConcreteLocation(35.75, 14.5, 0);
		ILocation location2 = createConcreteLocation(35.75, 14.508994, 0);
		float accuracy = Math.max(location1.getAccuracy(), location2.getAccuracy());
		assertEquals(1000.0, location1.distanceTo(location2), accuracy);

		// 500 km
		location1 = createConcreteLocation(40.67, 15.9, 0);
		location2 = createConcreteLocation(45, 17.641825, 0);
		accuracy = Math.max(location1.getAccuracy(), location2.getAccuracy());
		assertEquals(500000.0, location1.distanceTo(location2), accuracy);
		
		// 100 m
		location1 = createConcreteLocation(40.67, 15.9, 0);
		location2 = createConcreteLocation(40.67, 15.9009000, 0);
		accuracy = Math.max(location1.getAccuracy(), location2.getAccuracy());
		assertEquals(100.0, location1.distanceTo(location2), accuracy);

		// 10 m
		location1 = createConcreteLocation(40.67, 15.9, 0);
		location2 = createConcreteLocation(40.67, 15.9000899, 0);
		accuracy = Math.max(location1.getAccuracy(), location2.getAccuracy());
		assertEquals(10.0, location1.distanceTo(location2), accuracy);
	}
	
	
	@Test
	public void testGetSampleTime() 
	{
		Date beforeCreation = new Date();
		try 
		{
			Thread.sleep(1);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		ILocation location1 = createConcreteLocation(0, 0, 0);
		
		try 
		{
			Thread.sleep(1);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		assertTrue(location1.getSampleTime() < System.currentTimeMillis());
		assertTrue(location1.getSampleTime() > beforeCreation.getTime());
	}
}
